﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;
using Dao.Interface;
using NHibernate.Criterion;
using System.Data;
using System.Data.SqlClient;
using NHibernate;

namespace Dao
{
    public class NoteBookRepository : Repository<NoteBook>, INoteBookRepository
    {
        /// <summary>
        /// 获取笔记本集合
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <returns></returns>
        public IList<NoteBook> LoadAllNoteBook(object userID)
        {
            return this.Session.CreateCriteria(typeof(NoteBook))
                .CreateCriteria("UserInfo").Add(Restrictions.Eq("ID", userID))
                .List<NoteBook>();
        }

        /// <summary>
        /// 获取笔记本集合
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="delete">是否删除</param>
        /// <returns></returns>
        public IList<NoteBook> LoadAllNoteBook(object userID, bool delete)
        {
            return this.Session.CreateCriteria(typeof(NoteBook))
                .Add(Restrictions.Eq("MarkDelete", delete))
                .CreateCriteria("UserInfo").Add(Restrictions.Eq("ID", userID))
                .List<NoteBook>();
        }

        /// <summary>
        /// 获取笔记本集合
        /// </summary>
        /// <returns></returns>
        public IList<NoteBook> LoadAllShareNoteBook()
        {
            return this.Session.CreateCriteria(typeof(NoteBook))
                   .Add(Restrictions.Eq("MarkDelete", false)).Add(Restrictions.Eq("Share", true))
                   .List<NoteBook>();
        }

        /// <summary>
        /// 根据用户ID获取笔记本集合
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="share">是否共享</param>
        /// <returns></returns>
        public IList<NoteBook> LoadAllShareNoteBook(object userID, bool share)
        {
            return this.Session.CreateCriteria(typeof(NoteBook))
                .Add(Restrictions.Eq("MarkDelete", false)).Add(Restrictions.Eq("Share", share))
                .CreateCriteria("UserInfo").Add(Restrictions.Eq("ID", userID))
                .List<NoteBook>();
        }

    }
}
